package com.zbmsg.controller;

import java.util.HashMap;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.zbmsg.user.bean.User;
import com.zbmsg.user.service.IUserService;
import com.zbmsg.utils.common.Response;

@RestController
@RequestMapping("login")
public class LoginController {

	@Autowired
	private IUserService userService;

	@RequestMapping(value = "user/login", produces = "application/json; charset=utf-8", method = RequestMethod.POST)
	@ResponseBody
	public String login(@RequestParam(value = "userName", required = true)String userName) {
		HashMap<String, Object> obj = new HashMap<String, Object>();
		try {
		User user = this.userService.add(userName);
		obj.put("userId", user.getId());
		obj.put("userName", user.getName());
		obj.put("userHeadUrl", user.getHeadUrl());
		} catch (Exception e) {
			e.getMessage();
		}
		return Response.ok("登入成功",obj);
	}
}
